{% extends "master.html" %}

{% block title %}Home{% endblock %}
{%block tag %}{{tag}}{% endblock %}

{% block content %}
<h2>{{username}} sites</h2>

{% if not sites %}
<p>
  You apparently did not register any sites yet.
</p>
{% else %}
<p>
  You have currently {{ sites | length }} sites listed
</p>
{% endif %}

<p class="buttons indent">
  <a href="{{ url_for('site_new') }}">
    <input type="button" value="Register a new site" class="button">
  </a>
</p>

{% if sites %}
<table>
  <tr>
    <th>Site name</th>
    <th>Hosts</th>
    <th>Admin Active</th>
    <th>User Active</th>
    <th>Private</th>
    <th>Bandwith</th>
    <th>Last crawled</th>
  </tr>
  {% for site in sites %}
  <tr>
    <td rowspan="{% if site.hosts %}{{ site.hosts | length }}{% endif %}" class="matrix_section">
      <a href="{{ url_for('site_view', site_id=site.id) }}">
        {{ site.name }}
      </a>
    </td>
    {% if not site.hosts %}
    <td class="matrix_section"></td>
    <td class="matrix_section"></td>
    <td class="matrix_section"></td>
    <td class="matrix_section"></td>
    <td class="matrix_section"></td>
    <td class="matrix_section"></td>
    {% else %}
      {% for host in site.hosts %}
        {% if not loop.first %}
          </tr>
          <tr>
        {% endif %}

        {% if loop.last %}
          <td class="matrix_section {{ loop.cycle('matrix_odd', 'matrix_even') }}">
        {% else %}
          <td class="{{ loop.cycle('matrix_odd', 'matrix_even') }}">
        {% endif %}
          <a href="{{ url_for('host_view', host_id=host.id) }}">
            {{host.name}}
          </a>
        </td>

        {% if loop.last %}
          <td class="matrix_section {{ loop.cycle('matrix_odd', 'matrix_even') }}">
        {% else %}
          <td class="{{ loop.cycle('matrix_odd', 'matrix_even') }}">
        {% endif %}
          {{host.admin_active}}
        </td>

        {% if loop.last %}
          <td class="matrix_section {{ loop.cycle('matrix_odd', 'matrix_even') }}">
        {% else %}
          <td class="{{ loop.cycle('matrix_odd', 'matrix_even') }}">
        {% endif %}
          {{host.user_active}}
        </td>

        {% if loop.last %}
          <td class="matrix_section {{ loop.cycle('matrix_odd', 'matrix_even') }}">
        {% else %}
          <td class="{{ loop.cycle('matrix_odd', 'matrix_even') }}">
        {% endif %}
          {{host.private}}
        </td>

        {% if loop.last %}
          <td class="matrix_section {{ loop.cycle('matrix_odd', 'matrix_even') }}">
        {% else %}
          <td class="{{ loop.cycle('matrix_odd', 'matrix_even') }}">
        {% endif %}
          {{host.bandwidth_int}}
        </td>

        {% if loop.last %}
          <td class="matrix_section {{ loop.cycle('matrix_odd', 'matrix_even') }}">
        {% else %}
          <td class="{{ loop.cycle('matrix_odd', 'matrix_even') }}">
        {% endif %}
          {{host.last_crawled}}
        </td>

      {% endfor %}
    {% endif %}
  </tr>
  {% endfor %}
</table>
{% endif %}

{% endblock %}
